<template>
  <div>
    <div style="padding:30px;">
      <el-alert :closable="false" title="帖子管理" />
    </div>

    <template>
      <el-table
        :data="postData"
        style="width: 100%">
        <el-table-column
          prop="title"
          label="题目"
          width="180">
        </el-table-column>
        <el-table-column
          prop="userName"
          label="作者"
          width="180">
        </el-table-column>
        <el-table-column
          prop="dianzanNumber"
          label="点赞数">
        </el-table-column>
        <el-table-column
          prop=time
          label="发布时间"
          width="180">
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="100">
          <template slot-scope="scope">
            <el-button
              v-on:click="open(scope.row)"
              type="text"
              size="small"
            >删除帖子</el-button>
            <!-- <el-button type="text" size="small">编辑</el-button>-->
          </template>
        </el-table-column>
      </el-table>
    </template>


  </div>

</template>
<script>
  import {ApiService} from "@/api/apiService";

  export default {
    data() {
      return {
        postData: []
      }
    },
    mounted() {
      this.getPostMessage()
    },
    methods:{
      open(row) {
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.deletePost(row)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      deletePost(row){


        console.log("row"+row.id)//获取到帖子id
        const deletePost = new ApiService("/admin/deletePost")
        deletePost.getParams({
            postId:row.id
          }
        )
        location.reload();
      },
      getPostMessage(){

        const getPostMessage = new ApiService("/pethome/post")
        getPostMessage.getViewList().then(
          res=>{
            console.log("getPostMessage")
            this.postData = res.data
          }
        )
      }
    }
  }



</script>

<style scoped>

</style>
